<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix='sec'
	uri='http://www.springframework.org/security/tags'%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<script type="text/javascript" src="scripts/boot.js"></script>
</head>
<body style="border: 0px; margin: 0px; padding: 0px;width: 100%;height: 100%">
	<div class="mini-toolbar" style="border-bottom:0;padding:0px;">
		<table width="100%" border="0">
			 <tr>
			   	<td align="right"><span>字典表键(精确)</span></td>
			    <td><input id="keyName" class="mini-textbox" emptyText="请输入字典表键" style="width:150px;" onenter="onKeyEnter"/> </td>
			   	<td align="right"><span>字典表值(模糊)</span></td>
			    <td><input id="keyValue" class="mini-textbox" emptyText="请输入字典表值" style="width:150px;" onenter="onKeyEnter"/> </td>
			    <td align="right"><span>字典表类型(精确)</span></td>
			    <td>
			    <input id="typeName" style="width: 170px;" class="mini-combobox" valueField="keyName" textField="keyValue"
	        		url="dictionary_key_type_view.do" popupWidth="150px;" showNullItem="true" nullItemText="全部" popupHeight="130px;" emptyText="请输入字典表类型"/>
			    </td>
			    <td><a class="mini-button" iconCls="icon-search" onclick="search()">查询</a> </td>
			 </tr>
		</table>          
	</div>
	<div class="mini-toolbar" style="border-bottom:0;padding:0px;">
	    <table style="width:100%;">
	        <tr>
	            <td style="width:100%;">
	            	<sec:authorize url='/dictionary_add.do'>
	                <a class="mini-button" iconCls="icon-add" onclick="add()">增加</a>
	                </sec:authorize>
	                <sec:authorize url='/dictionary_edit.do'>
	                <a class="mini-button" iconCls="icon-edit" onclick="edit()">编辑</a>
	                </sec:authorize>
	                <sec:authorize url='/dictionary_delete.do'>
	                <a class="mini-button" iconCls="icon-remove" onclick="remove()">删除</a>    
	                </sec:authorize>   
	            </td>
	        </tr>
	    </table>           
	</div>
	<div class="mini-fit" >
		<div id="datagrid1" class="mini-datagrid" multiSelect="true" idField="id" pageSize="20" url="dictionary_view.do" style="width:100%;height:100%;">
			<div property="columns">
				<div type="indexcolumn"></div>
				<div type="checkcolumn" ></div>
				<div field="keyName" width="200" headerAlign="center" align="center">字典表键</div>
				<div field="keyValue" width="200" headerAlign="center" align="center">字典表值</div>
				<div field="chFieldVal" width="200" headerAlign="center" align="center">数据字段</div>
			</div>
		</div>
	</div>
<script type="text/javascript">
mini.parse();
var grid = mini.get("datagrid1");
grid.load();
//添加
function add() {
    mini.open({
        url: "dictionary_add.do",
        allowResize:false,
        title: "新增字典表信息", width: 400, height: 280,
        ondestroy: function (action) {
        	if(action == 'succ'){
        		mini.showMessageBox({
                    title: "提示",
                    showModal:false,
                    iconCls: "mini-messagebox-info",
                    message: "保存成功！",
                    timeout: 3000,
                    x: 'right',
                    y: 'bottom'
                });
	            grid.reload();
        	}
        }
    });
}

//修改
function edit() {
    var row = grid.getSelecteds();
    if (row.length == 1) {
        mini.open({
            url: "dictionary_edit.do",
            allowResize:false,
            title: "编辑字典表信息", width: 400, height: 250,
            onload: function () {
                var iframe = this.getIFrameEl();
                var data = { action: "edit" };
                iframe.contentWindow.SetData(data,row[0]);
            },
            ondestroy: function (action) {
            	if(action == 'succ'){
            		mini.showMessageBox({
                        title: "提示",
                        showModal:false,
                        iconCls: "mini-messagebox-info",
                        message: "修改成功！",
                        timeout: 3000,
                        x: 'right',
                        y: 'bottom'
                    });
                	grid.reload();
            	}
            }
        });
    } else {
    	mini.alert("请选中一条记录");
    }
}

//删除
function remove() {
	var rows = grid.getSelecteds();
    if (rows.length > 0) {
    	mini.confirm("确定删除选中记录？", "删除",
			function (action) {
				if (action == "ok") {
					var ids = [];
					for (var i = 0, l = rows.length; i < l; i++) {
					    var r = rows[i];
					    ids.push(r.id);
					}
					var id = ids.join(',');   
                   	grid.loading("操作中，请稍后......");
                       $.post(
                       	"dictionary_delete.do",
                       	{id:id},
                       	function(data){
                       		if(data.success){
                       			mini.showMessageBox({
                                    title: "提示",
                                    showModal:false,
                                    iconCls: "mini-messagebox-info",
                                    message: "已删除！",
                                    timeout: 3000,
                                    x: 'right',
                                    y: 'bottom'
                                });
                       		}else{
                       			mini.alert("数据错误！");
                       		}
                       		grid.reload();
                       	},"json");
                   }
               });
    } else {
    	mini.alert("请选中一条记录");
    }
}

function search() {
	var keyName = mini.get("keyName").getValue();
	var keyValue = mini.get("keyValue").getValue();
    var typeName = mini.get("typeName").getValue();
    grid.load({
    	keyName: keyName,
    	keyValue: keyValue,
    	typeName: typeName
   });
}

function onKeyEnter(e) {
    search();
}
</script>
</body>
</html>